/*
 * @lc app=leetcode.cn id=145 lang=javascript
 *
 * [145] 二叉树的后序遍历
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var postorderTraversal = function(root) {
  if (!root) return [];
  const stack_1 = [root];
  const ans_1 = [];

  while (stack_1.length > 0) {
    const cur = stack_1.pop();
    ans_1.push(cur.val);
    if (cur.left) stack_1.push(cur.left);
    if (cur.right) stack_1.push(cur.right);
  }

  return ans_1.reverse();
};
// @lc code=end

